package com.gitee.huxing.course;

import cn.hutool.core.date.DateUtil;
import com.gitee.huxing.api.Order;
import com.gitee.huxing.api.OrderService;
import com.gitee.huxing.api.User;
import com.gitee.huxing.api.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@Slf4j
@SpringBootApplication
public class DubboDemoConsumerApplication implements CommandLineRunner {

    @DubboReference(version = "1.0.0", url = "dubbo://127.0.0.1:12345")
    private UserService userService;

    @DubboReference(version = "1.0.0", url = "dubbo://127.0.0.1:12345")
    private OrderService orderService;

    public static void main(String[] args) {
        SpringApplication.run(DubboDemoConsumerApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        log.info("消费者服务启动: {}", DateUtil.now());
        User user = userService.findById(1);
        System.out.println("find user id=1 from server: " + user.getName());
        Order order = orderService.findOrderById(1992129);
        System.out.println(String.format("find order name=%s, amount=%f",order.getName(),
                order.getAmount()));
    }
}
